package com.study.blog.controller;

import com.study.blog.common.aop.LogAnnotation;
import com.study.blog.common.cache.Cache;
import com.study.blog.service.ArticleService;
import com.study.blog.vo.Result;
import com.study.blog.vo.parms.ArticleParam;
import com.study.blog.vo.parms.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 1
 * @data 2022/2/15
 */
@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 首页文章列表
     * @param pageParams
     * @return
     */
    @PostMapping
    @LogAnnotation(module = "文章",operator = "获取文章列表")
    public Result listArticle(@RequestBody PageParams pageParams){

        return articleService.listArticle(pageParams);
    }

    /**
     * 最热文章
     */
    @PostMapping("hot")
    @Cache(expire = 5*60*1000,name = "hot_article")
    public Result hotArticle(){
        int limit = 3;
        return articleService.hotArticle(limit);
    }

    /**
     * 最新文章
     */
    @PostMapping("new")
    public Result newArticle(){
        int limit = 3;
        return articleService.newArticle(limit);
    }


    /**
     * 最新文章
     */
    @PostMapping("listArchives")
    public Result listArchives(){

        return articleService.listArchives();
    }

    /**
     * 阅读文章
     */
    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }

    /**
     * 发布文章
     */
    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
       return articleService.publish(articleParam);
    }
}
